<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>专业舒尔特方格训练</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
        }
        
        body {
            background: linear-gradient(135deg, #FFF8F0, #FFEDD8);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 15px;
            color: #5D4037;
            overflow-x: hidden;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
        }
        
        .container {
            max-width: 800px;
            width: 100%;
            margin: 0 auto;
            text-align: center;
            padding: 10px;
        }
        
        header {
            margin: 15px 0 20px;
            text-align: center;
        }
        
        h1 {
            font-size: 2.2rem;
            color: #795548;
            margin-bottom: 8px;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
            background: linear-gradient(45deg, #8D6E63, #5D4037);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 700;
        }
        
        .subtitle {
            font-size: 1rem;
            color: #8D6E63;
            max-width: 600px;
            margin: 0 auto;
            line-height: 1.5;
            padding: 0 10px;
        }
        
        .stats-container {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin: 15px 0;
            flex-wrap: wrap;
        }
        
        .stat-box {
            background: rgba(255, 236, 179, 0.85);
            border-radius: 14px;
            padding: 14px 20px;
            min-width: 140px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.08);
            border: 2px solid #FFD54F;
            flex: 1;
            max-width: 160px;
        }
        
        .stat-label {
            font-size: 0.95rem;
            font-weight: 600;
            margin-bottom: 6px;
            color: #5D4037;
        }
        
        .stat-value {
            font-size: 1.6rem;
            font-weight: 800;
            color: #E65100;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
        }
        
        .grid-container {
            display: grid;
            grid-template-columns: repeat(5, 1fr);
            gap: 10px;
            max-width: 500px;
            margin: 20px auto;
            padding: 20px;
            background: rgba(255, 204, 188, 0.6);
            border-radius: 20px;
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
            border: 2px solid #FFAB91;
        }
        
        .grid-item {
            aspect-ratio: 1;
            background: #FFFFFF;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.6rem;
            font-weight: 800;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
            color: #5D4037;
            user-select: none;
            position: relative;
            overflow: hidden;
            border: 1px solid #FFCCBC;
        }
        
        .grid-item:hover, .grid-item:active {
            transform: translateY(-2px);
            box-shadow: 0 6px 10px rgba(0,0,0,0.15);
        }
        
        .grid-item.correct {
            animation: correctAnimation 0.6s ease;
        }
        
        .grid-item.completed {
            background: #C8E6C9;
            color: #2E7D32;
            border-color: #A5D6A7;
        }
        
        .grid-item.completed::after {
            content: "✓";
            position: absolute;
            bottom: 4px;
            right: 4px;
            font-size: 1rem;
            color: #2E7D32;
        }
        
        @keyframes correctAnimation {
            0% { transform: scale(1); }
            50% { transform: scale(0.85); }
            100% { transform: scale(1); }
        }
        
        .controls {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin: 25px 0;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 14px 26px;
            font-size: 1.1rem;
            font-weight: 700;
            border: none;
            border-radius: 40px;
            cursor: pointer;
            transition: all 0.3s ease;
            min-width: 150px;
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
            position: relative;
            overflow: hidden;
            z-index: 1;
        }
        
        .btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.2);
            z-index: -1;
            transform: scaleX(0);
            transform-origin: left;
            transition: transform 0.3s ease;
        }
        
        .btn:hover::before {
            transform: scaleX(1);
        }
        
        .btn-restart {
            background: #FFB74D;
            color: #5D4037;
        }
        
        .btn-new {
            background: #81C784;
            color: #1B5E20;
        }
        
        .btn:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.2);
        }
        
        .btn:active {
            transform: translateY(1px);
        }
        
        .modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.85);
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 1000;
            opacity: 0;
            visibility: hidden;
            transition: all 0.4s ease;
        }
        
        .modal.active {
            opacity: 1;
            visibility: visible;
        }
        
        .modal-content {
            background: linear-gradient(145deg, #FFF8F0, #FFECB3);
            border-radius: 20px;
            padding: 35px;
            text-align: center;
            max-width: 480px;
            width: 90%;
            transform: translateY(30px);
            transition: transform 0.4s ease;
            box-shadow: 0 20px 40px rgba(0,0,0,0.35);
            border: 2px solid #FFD54F;
            position: relative;
            overflow: hidden;
        }
        
        .modal.active .modal-content {
            transform: translateY(0);
        }
        
        .modal h2 {
            font-size: 2.2rem;
            color: #E65100;
            margin-bottom: 20px;
            text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
            position: relative;
            z-index: 1;
        }
        
        .modal p {
            font-size: 1.4rem;
            margin: 15px 0;
            color: #5D4037;
            font-weight: 600;
            position: relative;
            z-index: 1;
        }
        
        .record-badge {
            background: linear-gradient(45deg, #FFD54F, #FFB74D);
            padding: 8px 20px;
            border-radius: 30px;
            font-weight: 700;
            display: inline-block;
            margin-top: 15px;
            font-size: 1.2rem;
            color: #5D4037;
            box-shadow: 0 4px 8px rgba(0,0,0,0.15);
            position: relative;
            z-index: 1;
        }
        
        .modal-btn {
            margin-top: 25px;
            padding: 12px 40px;
            font-size: 1.1rem;
            background: linear-gradient(45deg, #4CAF50, #81C784);
            color: white;
            border: none;
            border-radius: 40px;
            cursor: pointer;
            font-weight: 700;
            transition: all 0.3s ease;
            box-shadow: 0 4px 8px rgba(0,0,0,0.2);
            position: relative;
            z-index: 1;
        }
        
        .modal-btn:hover {
            background: linear-gradient(45deg, #388E3C, #4CAF50);
            transform: translateY(-3px);
            box-shadow: 0 6px 12px rgba(0,0,0,0.25);
        }
        
        .instructions {
            background: rgba(255, 236, 179, 0.7);
            border-radius: 16px;
            padding: 20px;
            margin: 25px auto;
            max-width: 600px;
            border: 2px solid #FFD54F;
        }
        
        .instructions h3 {
            color: #5D4037;
            margin-bottom: 15px;
            font-size: 1.3rem;
        }
        
        .instructions ul {
            text-align: left;
            padding-left: 20px;
        }
        
        .instructions li {
            margin: 10px 0;
            line-height: 1.5;
            font-size: 0.95rem;
        }
        
        .progress-bar {
            height: 6px;
            background: #E0E0E0;
            border-radius: 3px;
            margin: 15px auto;
            max-width: 480px;
            overflow: hidden;
            box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
        }
        
        .progress {
            height: 100%;
            background: linear-gradient(90deg, #81C784, #4CAF50);
            width: 0%;
            transition: width 0.3s ease;
        }
        
        /* 微信浏览器特别优化 */
        @media screen and (-webkit-min-device-pixel-ratio:0) and (max-width: 1024px) {
            .grid-item {
                font-size: 1.4rem;
            }
            
            .btn {
                min-width: 140px;
                padding: 12px 22px;
            }
            
            .modal-content {
                padding: 25px;
            }
        }
        
        /* 响应式设计 */
        @media (max-width: 600px) {
            .grid-container {
                gap: 8px;
                padding: 15px;
            }
            
            .grid-item {
                font-size: 1.3rem;
            }
            
            .stat-box {
                padding: 12px 15px;
                min-width: 120px;
            }
            
            .stat-value {
                font-size: 1.4rem;
            }
            
            h1 {
                font-size: 1.8rem;
            }
            
            .controls {
                gap: 12px;
            }
            
            .btn {
                padding: 12px 20px;
                min-width: 130px;
                font-size: 1rem;
            }
            
            .modal-content {
                padding: 20px;
            }
            
            .modal h2 {
                font-size: 1.8rem;
            }
            
            .modal p {
                font-size: 1.2rem;
            }
            
            .instructions {
                padding: 15px;
            }
        }
        
        @media (max-width: 400px) {
            .grid-container {
                gap: 6px;
            }
            
            .grid-item {
                font-size: 1.1rem;
            }
            
            .stat-box {
                padding: 10px 12px;
                min-width: 110px;
            }
            
            .instructions {
                padding: 12px;
            }
            
            .instructions li {
                font-size: 0.85rem;
            }
        }
        
        footer {
            margin-top: 25px;
            color: #8D6E63;
            font-size: 0.9rem;
            text-align: center;
            padding: 15px;
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>专业舒尔特方格训练</h1>
            <p class="subtitle">提升注意力、视觉感知和反应速度的专业训练工具 - 按顺序点击1-25的所有数字</p>
        </header>
        
        <div class="stats-container">
            <div class="stat-box">
                <div class="stat-label">当前用时</div>
                <div class="stat-value" id="current-time">0.000 秒</div>
            </div>
            <div class="stat-box">
                <div class="stat-label">最佳成绩</div>
                <div class="stat-value" id="best-time">0.000 秒</div>
            </div>
        </div>
        
        <div class="progress-bar">
            <div class="progress" id="progress"></div>
        </div>
        
        <div class="grid-container" id="grid">
            <!-- 动态生成网格 -->
        </div>
        
        <div class="controls">
            <button class="btn btn-restart" id="restart-btn">重新开始</button>
            <button class="btn btn-new" id="new-game-btn">新游戏</button>
        </div>
        
        <div class="instructions">
            <h3>训练说明：</h3>
            <ul>
                <li>按数字顺序点击1到25的所有方格</li>
                <li><strong>正确点击</strong>：方格变绿并显示动画效果</li>
                <li><strong>错误点击</strong>：无任何反应</li>
                <li><strong>重新开始</strong>按钮：重置计时器但保持当前布局</li>
                <li><strong>新游戏</strong>按钮：完全重新洗牌并开始新游戏</li>
                <li>目标：尽可能快地完成挑战并打破个人记录！</li>
            </ul>
        </div>
    </div>
    
    <div class="modal" id="result-modal">
        <div class="modal-content">
            <h2>挑战完成!</h2>
            <p id="completion-time">用时 0.000 秒</p>
            <p id="record-message">恭喜打破记录!</p>
            <div class="record-badge">新纪录!</div>
            <button class="modal-btn" id="modal-close-btn">再玩一次</button>
        </div>
    </div>
    
    <footer>
        专业级舒尔特方格训练  | © 2025
    </footer>
	<script src="https://cdn.bootcdn.net/ajax/libs/vConsole/3.3.4/vconsole.min.js"></script>
    <script>
	
	

  // 初始化
  var vConsole = new VConsole();
  console.log('Hello world');

	
        // 游戏状态变量
        let gridNumbers = [];
        let currentNumber = 1;
        let startTime = 0;
        let timer = null;
        //let bestTime = localStorage.getItem('schulteBestTime') || Infinity;
		
		let bestTime = parseFloat(localStorage.getItem('schulteBestTime')) || Infinity;
		
		console.log(bestTime,"bestTime")
		
        let audioContext = null;
        let currentClickSound = null;
        let successSound = null;
        
        // DOM元素
        const grid = document.getElementById('grid');
        const currentTimeEl = document.getElementById('current-time');
        const bestTimeEl = document.getElementById('best-time');
        const restartBtn = document.getElementById('restart-btn');
        const newGameBtn = document.getElementById('new-game-btn');
        const resultModal = document.getElementById('result-modal');
        const completionTimeEl = document.getElementById('completion-time');
        const recordMessageEl = document.getElementById('record-message');
        const modalCloseBtn = document.getElementById('modal-close-btn');
        const progressEl = document.getElementById('progress');
        
        // 初始化游戏
        function initGame() {
            // 显示最佳成绩
            updateBestTimeDisplay();
            
            // 创建网格
            createGrid();
            
            // 初始化音频
            initAudio();
            
            // 事件监听
            restartBtn.addEventListener('click', restartGame);
            newGameBtn.addEventListener('click', newGame);
            modalCloseBtn.addEventListener('click', closeModal);
            
            // 微信浏览器特别处理
            handleWechatCompatibility();
        }
        
        // 处理微信浏览器兼容性问题
        function handleWechatCompatibility() {
            // 修复微信浏览器中可能出现的空白网格问题
            if (grid.children.length === 0) {
                createGrid();
            }
            
            // 添加微信浏览器专用样式
            if (navigator.userAgent.match(/MicroMessenger/i)) {
                document.body.classList.add('wechat-browser');
            }
        }
        
        // 创建网格
        function createGrid() {
            grid.innerHTML = '';
            gridNumbers = generateNumbers();
            
            gridNumbers.forEach(num => {
                const cell = document.createElement('div');
                cell.className = 'grid-item';
                cell.textContent = num;
                cell.dataset.number = num;
                cell.addEventListener('click', () => handleCellClick(num, cell));
                grid.appendChild(cell);
            });
            
            // 重置进度条
            progressEl.style.width = '0%';
        }
        
        // 生成1-25的随机数字数组
        function generateNumbers() {
            const numbers = Array.from({length: 25}, (_, i) => i + 1);
            return shuffleArray(numbers);
        }
        
        // Fisher-Yates洗牌算法
        function shuffleArray(array) {
            const newArray = [...array];
            for (let i = newArray.length - 1; i > 0; i--) {
                const j = Math.floor(Math.random() * (i + 1));
                [newArray[i], newArray[j]] = [newArray[j], newArray[i]];
            }
            return newArray;
        }
        
        // 处理格子点击
        function handleCellClick(number, cell) {
            // 游戏未开始，点击第一个数字开始
            if (currentNumber === 1 && number === 1) {
                startTimer();
            }
            
            // 正确点击
            if (number === currentNumber) {
                // 播放正确音效
                playClickSound();
                
                // 添加完成状态和动画
                cell.classList.add('completed', 'correct');
                
                // 更新进度条
                progressEl.style.width = `${(currentNumber / 25) * 100}%`;
                
                // 移除动画类以便下次使用
                setTimeout(() => {
                    cell.classList.remove('correct');
                }, 600);
                
                // 更新当前数字
                currentNumber++;
                
                // 检查是否完成
                if (currentNumber > 25) {
                    endGame();
                }
            }
            // 错误点击 - 无响应（根据要求）
        }
        
        // 开始计时器
        function startTimer() {
            startTime = performance.now();
            clearInterval(timer);
            
            timer = setInterval(() => {
                const elapsed = (performance.now() - startTime) / 1000;
                currentTimeEl.textContent = elapsed.toFixed(3) + " 秒";
            }, 10);
        }
        
        // 结束游戏
        function endGame() {
            clearInterval(timer);
            const endTime = performance.now();
            const elapsedTime = (endTime - startTime) / 1000;
            
            // 播放完成音效
            playSuccessSound();
            
            // 检查是否打破记录
            const isNewRecord = elapsedTime < bestTime;
            
            if (isNewRecord) {
                bestTime = elapsedTime;
                localStorage.setItem('schulteBestTime', bestTime);
                updateBestTimeDisplay();
                recordMessageEl.textContent = "恭喜打破记录!";
                recordMessageEl.style.display = "block";
            } else {
                recordMessageEl.style.display = "none";
            }
            
            // 更新完成时间显示
            completionTimeEl.textContent = `用时 ${elapsedTime.toFixed(3)} 秒`;
            
            // 显示结果弹窗
            resultModal.classList.add('active');
        }
        
        // 重新开始游戏（保持当前布局）
        function restartGame() {
            currentNumber = 1;
            startTime = 0;
            clearInterval(timer);
            currentTimeEl.textContent = "0.000 秒";
            progressEl.style.width = '0%';
            
            // 重置所有格子样式
            const cells = document.querySelectorAll('.grid-item');
            cells.forEach(cell => {
                cell.classList.remove('correct', 'completed');
            });
        }
        
        // 新游戏（重新洗牌）
        function newGame() {
            restartGame();
            createGrid();
        }
        
        // 关闭结果弹窗
        function closeModal() {
            resultModal.classList.remove('active');
            newGame();
        }
        
        // 更新最佳成绩显示
        function updateBestTimeDisplay() {
            if (bestTime === Infinity) {
                bestTimeEl.textContent = "暂无记录";
            } else {
                bestTimeEl.textContent = bestTime.toFixed(3) + " 秒";
            }
        }
        
        // 初始化音频
        function initAudio() {
            try {
                // 创建音频上下文
                if (!audioContext) {
                    audioContext = new (window.AudioContext || window.webkitAudioContext)();
                }
                
                // 创建正确点击音效
                currentClickSound = () => {
                    if (!audioContext) return;
                    
                    const oscillator = audioContext.createOscillator();
                    const gainNode = audioContext.createGain();
                    
                    oscillator.type = 'sine';
                    oscillator.frequency.setValueAtTime(784.0, audioContext.currentTime);
                    oscillator.frequency.setValueAtTime(987.77, audioContext.currentTime + 0.05);
                    
                    gainNode.gain.setValueAtTime(0.3, audioContext.currentTime);
                    gainNode.gain.exponentialRampToValueAtTime(0.01, audioContext.currentTime + 0.3);
                    
                    oscillator.connect(gainNode);
                    gainNode.connect(audioContext.destination);
                    
                    oscillator.start();
                    oscillator.stop(audioContext.currentTime + 0.3);
                };
                
                // 创建成功音效
                successSound = () => {
                    if (!audioContext) return;
                    
                    const oscillator = audioContext.createOscillator();
                    const gainNode = audioContext.createGain();
                    
                    oscillator.type = 'sine';
                    const now = audioContext.currentTime;
                    
                    oscillator.frequency.setValueAtTime(523.25, now);
                    oscillator.frequency.setValueAtTime(659.25, now + 0.2);
                    oscillator.frequency.setValueAtTime(783.99, now + 0.4);
                    oscillator.frequency.setValueAtTime(1046.50, now + 0.6);
                    
                    gainNode.gain.setValueAtTime(0.4, now);
                    gainNode.gain.exponentialRampToValueAtTime(0.4, now + 0.7);
                    gainNode.gain.exponentialRampToValueAtTime(0.01, now + 0.9);
                    
                    oscillator.connect(gainNode);
                    gainNode.connect(audioContext.destination);
                    
                    oscillator.start();
                    oscillator.stop(now + 0.9);
                };
            } catch (e) {
                console.log("音频初始化失败:", e);
                // 降级处理：无音频
                currentClickSound = () => {};
                successSound = () => {};
            }
        }
        
        // 播放点击音效
        function playClickSound() {
            if (currentClickSound) {
                currentClickSound();
            }
        }
        
        // 播放成功音效
        function playSuccessSound() {
            if (successSound) {
                successSound();
            }
        }
        
        // 页面加载完成后初始化游戏
        document.addEventListener('DOMContentLoaded', initGame);
        
        // 微信浏览器页面恢复处理
        document.addEventListener('visibilitychange', function() {
            if (!document.hidden) {
                // 页面重新可见时检查网格
                if (grid.children.length === 0) {
                    createGrid();
                }
            }
        });
        
        // 微信浏览器resize事件处理
        window.addEventListener('resize', function() {
            // 修复微信浏览器中可能出现的布局问题
            if (grid.children.length > 0) {
                const firstCell = grid.children[0];
                if (firstCell.offsetHeight === 0) {
                    createGrid();
                }
            }
        });
    </script>
</body>
</html>